package com.lineage.data.npc.quest;

import com.lineage.data.cmd.CreateNewItem;
import com.lineage.data.executor.NpcExecutor;
import com.lineage.data.quest.IllusionistLv45_1;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_CloseList;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Npc_WcorpseC extends NpcExecutor {
  private static final Log _log = LogFactory.getLog(Npc_WcorpseC.class);
  
  public static NpcExecutor get() {
    return new Npc_WcorpseC();
  }
  
  public int type() {
    return 3;
  }
  
  public void talk(L1PcInstance pc, L1NpcInstance npc) {
    try {
      if (pc.isCrown()) {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse7"));
      } else if (pc.isKnight()) {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse7"));
      } else if (pc.isElf()) {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse7"));
      } else if (pc.isWizard()) {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse7"));
      } else if (pc.isDarkelf()) {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse7"));
      } else if (pc.isDragonKnight()) {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse7"));
      } else if (pc.isIllusionist()) {
        if (pc.getQuest().isStart(IllusionistLv45_1.QUEST.get_id())) {
          if (!pc.getInventory().checkItem(49196)) {
            pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse8"));
          } else {
            pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse7"));
          } 
        } else {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse7"));
        } 
      } else {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse7"));
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void action(L1PcInstance pc, L1NpcInstance npc, String cmd, long amount) {
    boolean isCloseList = false;
    if (cmd.equalsIgnoreCase("a")) {
      if (pc.getQuest().isStart(IllusionistLv45_1.QUEST.get_id())) {
        if (!pc.getInventory().checkItem(49196)) {
          L1ItemInstance item = pc.getInventory().checkItemX(49192, 1L);
          if (item != null) {
            pc.getInventory().removeItem(item, 1L);
            pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "wcorpse9"));
            CreateNewItem.createNewItem(pc, 49196, 1L);
          } 
        } else {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
          isCloseList = true;
        } 
      } else {
        isCloseList = true;
      } 
    } else {
      isCloseList = true;
    } 
    if (isCloseList)
      pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId())); 
  }
}
